local liufang = fk.CreateSkill{
  name = "xiaobai__liufang",
}

Fk:loadTranslationTable{
  ["xiaobai__liufang"] = "流芳",
  [":xiaobai__liufang"] = "每回合限一次，你需要使用基本牌时，你可以翻转一张或三张手牌，"..
    "若明置牌花色数为一，你弃置所有暗置牌，然后视为使用之。"
}

local DIY = require "packages/diy_utility/diy_utility"

liufang:addEffect("viewas", {
  anim_type = "control",
  pattern = ".|.|.|.|.|basic",
  interaction = function (self, player)
    local card_names = Fk:getAllCardNames("b")
    local can_use = player:getViewAsCardNames(liufang.name, card_names)
    if #can_use == 0 then return end
    return UI.CardNameBox{
      choices = can_use,
      all_choices = card_names
    }
  end,
  card_filter = function (self, player, to_select, selected, selected_targets)
    return table.contains(player:getCardIds(Player.Hand), to_select) and #selected < 3
  end,
  view_as = function (self, player, cards)
    if #cards ~= 1 and #cards ~= 3 then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = liufang.name
    card.fake_subcards = cards
    return card
  end,
  before_use = function (self, player, use)
    local cards = use.card.fake_subcards
    local shownCards = DIY.getShownCards(player)
    for _, cid in ipairs(cards) do
      if table.contains(shownCards, cid) then
        DIY.hideCards(player, cid)
      else
        DIY.showCards(player, cid)
      end
    end
    shownCards = DIY.getShownCards(player)
    local hideCards = table.filter(player:getCardIds(Player.Hand), function (cid)
      return not table.contains(shownCards, cid)
    end)
    local suits = {}
    for _, cid in ipairs(shownCards) do
      local suit = Fk:getCardById(cid).suit
      table.insertIfNeed(suits, suit)
    end
    if #suits > 1  then
      return liufang.name
    end
    player.room:throwCard(hideCards, liufang.name, player)
  end,
  enabled_at_play = function (self, player)
    return player:usedSkillTimes(liufang.name) == 0
  end,
  enabled_at_response =function (self, player, response)
    return player:usedSkillTimes(liufang.name) == 0 and not response
  end
})

return liufang